home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / SETVECT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.2 KB  |  40 lines

  1. /* SETVECT.C --- p. 670 */
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #define TIMER_TICK  0x1c
  5. unsigned long tickcount = 0;
  6. void interrupt our_handler(void);
  7. main()
  8. {
  9.     unsigned c;
  10.     void interrupt (*old_handler)();
  11.     unsigned intno = TIMER_TICK;
  12.     old_handler = getvect(intno);
  13.             /* Print out address of the old handler using the %p
  14.              * format */
  15.     printf("\nThe address of the old handler is: %Fp\n", old_handler);
  16.                 /* Install the new handler named our_handler
  17.                 * Disable interrupts when changing handler */
  18.     disable();
  19.     setvect(intno, our_handler);
  20.     enable();
  21.     printf("Installed new handler: %p\n", our_handler);
  22.     printf("Hit Q to quit: ");
  23.  
  24.     while((c=getch()) != 'q');        /* Keep looping till 'q' */
  25.         /* Reset vector and print the tickcounter.  Again disable
  26.          * interrupts when doing this. */
  27.     disable();
  28.     setvect(intno, old_handler);
  29.     enable();
  30.     printf("The tick counter is now: %ld\n", tickcount);
  31. }
  32.                     /*-------------------------------*/
  33. void interrupt our_handler()
  34. {
  35.         /* Our handler simply increments a counter.  But this
  36.         * will be proof enough that the handler works because
  37.         * we are not calling it explicitly in the main program
  38.         * and the only way it get called is via INT 1Ch. */
  39.     tickcount++;
  40. }